####################################################################
## author:    Robert A. Huber
## contact:   robert.huber@ir.gess.ethz.ch
## file name: pc_uk_robustness.R
## Context:   Populism and Climate Sceptism, individuals from BES
## started:   2016-10-12
## Summary:   runs Robustness Checks
######################################################################

minPop <- min(df_bes$populism, na.rm = T)
maxPop <- max(df_bes$populism, na.rm = T)

# Robustness Check --------------------------------------------------------

# Climate Change ----------------------------------------------------------

mcc.2_lr <- multinom(formula(paste0("climateChange ~ populism * lr_scale", cUK)), data = df_bes, weights = df_bes$wt_full_w7, maxit = 1000)
summary(mcc.2_lr)

# Interaction Plot for mcc2 -----------------------------------------------


fit.effR <- effect("populism*lr_scale", mcc.2_lr, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                              lr_scale = seq(1,10, length.out = 10)),
                   x.var="lr_scale", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob, 
                        fit.effR$upper.prob)

#plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue"), rug=FALSE, main = "", 
#     ylab = "Probability", xlab="Populismus")

cc2 <- c(PredPropR$prob.Climate.changing.due.to.human.activity, PredPropR$prob.Climate.changing.but.not.due.to.human.activity, PredPropR$prob.Climate.not.changing, PredPropR$prob.Don.t.know)
lr_scale <- c(rep(PredPropR$lr_scale, 4))
populism <- rep(c(-2,2),40)
lwrCI <- c(PredPropR$L.prob.Climate.changing.due.to.human.activity, PredPropR$L.prob.Climate.changing.but.not.due.to.human.activity, PredPropR$L.prob.Climate.not.changing, PredPropR$L.prob.Don.t.know)
uprCI <- c(PredPropR$U.prob.Climate.changing.due.to.human.activity, PredPropR$U.prob.Climate.changing.but.not.due.to.human.activity, PredPropR$U.prob.Climate.not.changing, PredPropR$U.prob.Don.t.know)
response <- rep(c("is changing due to human activity", "is changing but not due to human activity", "is not changing", "Do not know"), each=20)

df_cc2 <- data.frame(cc2,lr_scale, populism, lwrCI, uprCI, response)
df_cc2$response <- factor(df_cc2$response, levels = c("is changing due to human activity", "is changing but not due to human activity", "is not changing", "Do not know"))


pcc2_RBC <- ggplot(df_cc2, aes(x=lr_scale, y = cc2)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI, fill= factor(populism)), alpha =.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  facet_wrap(~response) +
  ggtitle("On the subject of climate change do you think the world's climate ...") +
  theme(strip.background = element_rect(fill = 'white'))+
  theme(text = element_text(size=20))
pcc2_RBC

# Environment vs. Growth --------------------------------------------------

meG.2_lr <- lm(formula(paste0("enviroGrowth ~ populism * lr_scale", cUK)), data = df_bes, weights = df_bes$wt_full_w7)
summary(meG.2_lr)


# Interaction PLot meG.2 - FIT --------------------------------------------

fit.effR <- effect("populism*lr_scale", meG.2_lr, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                              lr_scale = seq(1,10, length.out = 10)),
                   x.var="lr_scale", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$fit, fit.effR$lower, 
                        fit.effR$upper)

peG2_RBC <- ggplot(PredPropR, aes(x=lr_scale, y = fit.effR.fit)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=fit.effR.upper, ymin=fit.effR.lower, fill= factor(populism)), alpha=.5) +
  theme_tufte() +
  ylab("Prediction") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  ggtitle("Environmental protection vs. economic growth")+
  theme(text = element_text(size=20))
peG2_RBC

# Interaction Plot meG.3 MARGINS--------------------------------------------------

cov <- vcov(meG.2_lr)

beta.hat <- coef(meG.2_lr)

z <- seq(1, length.out = 11)

dy.dx.3eG <- beta.hat[2] + beta.hat[length(beta.hat)]*z
se.dy.dx.3eG <- sqrt(cov[2,2] + z^2*cov[length(beta.hat),length(beta.hat)] + 2*z*cov[2,length(beta.hat)])

upr.3eG <- dy.dx.3eG + 1.645 * se.dy.dx.3eG
lwr.3eG <- dy.dx.3eG - 1.645 * se.dy.dx.3eG

df_eG2 <- data.frame(dy.dx.3eG, se.dy.dx.3eG, z, upr.3eG, lwr.3eG)

p_eG2_RBC_margins <- ggplot(df_eG2, aes(x=z, y=dy.dx.3eG)) +
  geom_line() + 
  geom_line(aes(y= lwr.3eG, x= z), linetype = "dashed") +
  geom_line(aes(y= upr.3eG, x= z), linetype = "dashed") +
  #geom_ribbon(aes(ymin=lwr,ymax=upr),alpha=0.1) +
  theme_tufte() +
  geom_hline(yintercept = 0) +
  xlab("Political ideology") +
  ylab("Marginal effect") +
  scale_x_continuous(breaks = c(seq(1:10)))+
  theme(text = element_text(size=20))
p_eG2_RBC_margins

# Environmental Protection ------------------------------------------------

# meP.1 <- multinom(formula(paste0("enviroProtection ~ populism + lr_scale", cUK)), data = df_bes, weights = df_bes$wt_full_w7)
# summary(meP.1)

meP.2_lr <- multinom(formula(paste0("enviroProtection ~ populism * lr_scale", cUK)), data = df_bes, weights = df_bes$wt_full_w7, maxit = 1000)
summary(meP.2_lr)

meP.3_lr <- multinom(formula(paste0("enviroProtection_RBC ~ populism * lr_scale", cUK)), data = df_bes, weights = df_bes$wt_full_w7, maxit = 1000)
summary(meP.3_lr)

# Interaction Plot meP.2 --------------------------------------------------

fit.effR <- effect("populism*lr_scale", meP.2_lr, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                              lr_scale = seq(1,10, length.out = 10)),
                   x.var="lr_scale", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob, 
                        fit.effR$upper.prob)

# plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue", "green", "grey"), rug=FALSE, main = "", 
#      ylab = "Probability", xlab="Populismus")


eP2 <- c(PredPropR$prob.Gone.much.too.far, PredPropR$prob.Gone.too.far, PredPropR$prob.About.right, PredPropR$prob.Not.gone.far.enough, PredPropR$prob.Not.gone.nearly.far.enough, PredPropR$prob.Don.t.know)
lr_scale <- c(rep(PredPropR$lr_scale, 6))
populism <- rep(c(-2,2),60)
lwrCI <- c(PredPropR$L.prob.Gone.much.too.far, PredPropR$L.prob.Gone.too.far, PredPropR$L.prob.About.right, PredPropR$L.prob.Not.gone.far.enough, PredPropR$L.prob.Not.gone.nearly.far.enough, PredPropR$L.prob.Don.t.know)
uprCI <- c(PredPropR$U.prob.Gone.much.too.far, PredPropR$U.prob.Gone.too.far, PredPropR$U.prob.About.right, PredPropR$U.prob.Not.gone.far.enough, PredPropR$U.prob.Not.gone.nearly.far.enough, PredPropR$U.prob.Don.t.know)
response <- rep(c("Gone much too far", "Gone too far", "About right", "Not gone far enough", "Not gone nearly far enough", "Do not know"), each=20)

df_eP2 <- data.frame(eP2,lr_scale, populism, lwrCI, uprCI, response)
df_eP2$response <- factor(df_eP2$response, levels = c("Gone much too far", "Gone too far", "About right", "Not gone far enough", "Not gone nearly far enough", "Do not know"))


peP2_RBC <- ggplot(df_eP2, aes(x=lr_scale, y = eP2)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI, fill= factor(populism)), alpha =.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  facet_wrap(~response) +
  ggtitle("Do you think that measures to protect the environment\nhave gone too far or not far enough?") +
  theme(strip.background = element_rect(fill = 'white'))+
  theme(text = element_text(size=20))
peP2_RBC


# Interaction Plot RBC meP3 -----------------------------------------------

fit.effR <- effect("populism*lr_scale", meP.3_lr, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                              lr_scale = seq(1,10, length.out = 10)),
                   x.var="lr_scale", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob, 
                        fit.effR$upper.prob)

# plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue", "green", "grey"), rug=FALSE, main = "", 
#      ylab = "Probability", xlab="Populismus")


eP3 <- c(PredPropR$prob.Gone.too.far, PredPropR$prob.About.right, PredPropR$prob.Not.enough, PredPropR$prob.Don.t.know)
lr_scale <- c(rep(PredPropR$lr_scale, 4))
populism <- rep(c(-2,2),40)
uprCI <- c(PredPropR$U.prob.Gone.too.far, PredPropR$U.prob.About.right, PredPropR$U.prob.Not.enough, PredPropR$U.prob.Don.t.know)
lwrCI <- c(PredPropR$L.prob.Gone.too.far, PredPropR$L.prob.About.right, PredPropR$L.prob.Not.enough, PredPropR$L.prob.Don.t.know)
response <- rep(c("Gone too far", "About right", "Not gone far enough", "Do not know"), each=20)

df_eP3 <- data.frame(eP3,lr_scale, populism, lwrCI, uprCI, response)
df_eP3$response <- factor(df_eP3$response, levels = c("Gone too far", "About right", "Not gone far enough", "Do not know"))


peP3_RBC <- ggplot(df_eP3, aes(x=lr_scale, y = eP3)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI, fill= factor(populism)), alpha =.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  facet_wrap(~response) +
  ggtitle("Do you think that measures to protect the environment\nhave gone too far or not far enough?") +
  theme(strip.background = element_rect(fill = 'white'))+
  theme(text = element_text(size=20))
peP3_RBC



# Middle Categories Only --------------------------------------------------

# Robustness Check --------------------------------------------------------

# Climate Change ----------------------------------------------------------

mcc.2_res <- multinom(formula(paste0("climateChange ~ populism * lr", cUK)), data = df_bes, weights = df_bes$wt_full_w7, subset = df_bes$lr < 10 & df_bes$lr > 1, maxit = 1000)
summary(mcc.2_res)

# Interaction Plot for mcc2 -----------------------------------------------


fit.effR <- effect("populism*lr", mcc.2_res, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                        lr = seq(2,9, length.out = 8)),
                   x.var="lr", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob,
                        fit.effR$upper.prob)

#plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue"), rug=FALSE, main = "",
#     ylab = "Probability", xlab="Populismus")

cc2 <- c(PredPropR$prob.Climate.changing.due.to.human.activity, PredPropR$prob.Climate.changing.but.not.due.to.human.activity, PredPropR$prob.Climate.not.changing, PredPropR$prob.Don.t.know)
lr <- c(rep(PredPropR$lr, 4))
populism <- rep(c(minPop,maxPop),32)
lwrCI <- c(PredPropR$L.prob.Climate.changing.due.to.human.activity, PredPropR$L.prob.Climate.changing.but.not.due.to.human.activity, PredPropR$L.prob.Climate.not.changing, PredPropR$L.prob.Don.t.know)
uprCI <- c(PredPropR$U.prob.Climate.changing.due.to.human.activity, PredPropR$U.prob.Climate.changing.but.not.due.to.human.activity, PredPropR$U.prob.Climate.not.changing, PredPropR$U.prob.Don.t.know)
response <- rep(c("is changing due to human activity", "is changing but not due to human activity", "is not changing", "Do not know"), each=16)

df_cc2 <- data.frame(cc2,lr, populism, lwrCI, uprCI, response)
df_cc2$response <- factor(df_cc2$response, levels = c("is changing due to human activity", "is changing but not due to human activity", "is not changing", "Do not know"))


pcc2_res <- ggplot(df_cc2, aes(x=lr, y = cc2)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI, fill= factor(populism)), alpha=.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "Left", "3", "4", "5", "6", "7", "8", "Right", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  facet_wrap(~response) +
  ggtitle("On the subject of climate change do you think the world's climate ...") +
  theme(strip.background = element_rect(fill = 'white'))+
  theme(text = element_text(size=20))
pcc2_res

# Environment vs. Growth --------------------------------------------------

meG.2_res <- lm(formula(paste0("enviroGrowth ~ populism * lr", cUK)), data = df_bes, weights = df_bes$wt_full_w7, subset = df_bes$lr < 10 & df_bes$lr > 1)
summary(meG.2)

# Interaction Plot meG.2 -- Fit -------------------------------------------

fit.effR <- effect("populism*lr", meG.2_res, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                        lr = seq(2,9, length.out = 8)),
                   x.var="lr", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$fit, fit.effR$lower, 
                        fit.effR$upper)

peG2_res <- ggplot(PredPropR, aes(x=lr, y = fit.effR.fit)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=fit.effR.upper, ymin=fit.effR.lower, fill= factor(populism)), alpha =.5) +
  theme_tufte() +
  ylab("Prediction") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left","Left", "3", "4", "5", "6", "7", "8", "Right", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  ggtitle("Environmental protection (0) vs. economic growth (10)") +
  theme(text = element_text(size=20))
peG2_res

# Interaction Plot meG.2 -- Traditional --------------------------------------------------

cov <- vcov(meG.2_res)

beta.hat <- coef(meG.2_res)

z <- seq(1, length.out = 8)

dy.dx.3eG <- beta.hat[2] + beta.hat[length(beta.hat)]*z
se.dy.dx.3eG <- sqrt(cov[2,2] + z^2*cov[length(beta.hat),length(beta.hat)] + 2*z*cov[2,length(beta.hat)])

upr.3eG <- dy.dx.3eG + 1.645 * se.dy.dx.3eG
lwr.3eG <- dy.dx.3eG - 1.645 * se.dy.dx.3eG

df_eG2 <- data.frame(dy.dx.3eG, se.dy.dx.3eG, z, upr.3eG, lwr.3eG)

p_eG2_res_margins <- ggplot(df_eG2, aes(x=z, y=dy.dx.3eG)) +
  geom_line() + 
  geom_line(aes(y= lwr.3eG, x= z), linetype = "dashed") +
  geom_line(aes(y= upr.3eG, x= z), linetype = "dashed") +
  #geom_ribbon(aes(ymin=lwr,ymax=upr),alpha=0.1) +
  theme_tufte() +
  geom_hline(yintercept = 0) +
  xlab("Political ideology") +
  ylab("Marginal effect") +
  scale_x_continuous(breaks = c(seq(2:9)), labels=c("Left", "3", "4", "5", "6", "7", "8", "Right"))+
  theme(text = element_text(size=20))
p_eG2_res_margins

# Environmental Protection ------------------------------------------------

meP.2_res <- multinom(formula(paste0("enviroProtection ~ populism * lr", cUK)), data = df_bes, weights = df_bes$wt_full_w7, maxit = 1000, subset = df_bes$lr < 10 & df_bes$lr > 1)
summary(meP.2_res)

meP.3_res <- multinom(formula(paste0("enviroProtection_RBC ~ populism * lr", cUK)), data = df_bes, weights = df_bes$wt_full_w7,maxit = 1000, subset = df_bes$lr < 10 & df_bes$lr > 1)
summary(meP.3_res)

# Interaction Plot meP.2 --------------------------------------------------

fit.effR <- effect("populism*lr", meP.2_res, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                        lr = seq(2,9, length.out = 8)),
                   x.var="lr", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob,
                        fit.effR$upper.prob)

# plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue", "green", "grey"), rug=FALSE, main = "",
#      ylab = "Probability", xlab="Populismus")


eP2 <- c(PredPropR$prob.Gone.much.too.far, PredPropR$prob.Gone.too.far, PredPropR$prob.About.right, PredPropR$prob.Not.gone.far.enough, PredPropR$prob.Not.gone.nearly.far.enough, PredPropR$prob.Don.t.know)
lr <- c(rep(PredPropR$lr, 6))
populism <- rep(c(-2,2),48)
lwrCI <- c(PredPropR$L.prob.Gone.much.too.far, PredPropR$L.prob.Gone.too.far, PredPropR$L.prob.About.right, PredPropR$L.prob.Not.gone.far.enough, PredPropR$L.prob.Not.gone.nearly.far.enough, PredPropR$L.prob.Don.t.know)
uprCI <- c(PredPropR$U.prob.Gone.much.too.far, PredPropR$U.prob.Gone.too.far, PredPropR$U.prob.About.right, PredPropR$U.prob.Not.gone.far.enough, PredPropR$U.prob.Not.gone.nearly.far.enough, PredPropR$U.prob.Don.t.know)
response <- rep(c("Gone much too far", "Gone too far", "About right", "Not gone far enough", "Not gone nearly far enough", "Do not know"), each=16)

df_eP2 <- data.frame(eP2,lr, populism, lwrCI, uprCI, response)
df_eP2$response <- factor(df_eP2$response, levels = c("Gone much too far", "Gone too far", "About right", "Not gone far enough", "Not gone nearly far enough", "Do not know"))


peP2_res <- ggplot(df_eP2, aes(x=lr, y = eP2)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI, fill= factor(populism)), alpha=.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "Left", "3", "4", "5", "6", "7", "8", "Right", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  facet_wrap(~response) +
  ggtitle("Do you think that measures to protect the environment\nhave gone too far or not far enough?") +
  theme(strip.background = element_rect(fill = 'white')) +
  theme(text = element_text(size=20))
peP2_res


# peP3 Figures ------------------------------------------------------------

fit.effR <- effect("populism*lr", meP.3_res, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                        lr = seq(2,9, length.out = 8)),
                   x.var="lr", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob, 
                        fit.effR$upper.prob)

# plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue", "green", "grey"), rug=FALSE, main = "", 
#      ylab = "Probability", xlab="Populismus")


eP3 <- c(PredPropR$prob.Gone.too.far, PredPropR$prob.About.right, PredPropR$prob.Not.enough, PredPropR$prob.Don.t.know)
lr <- c(rep(PredPropR$lr, 4))
populism <- rep(c(-2,2),32)
uprCI <- c(PredPropR$U.prob.Gone.too.far, PredPropR$U.prob.About.right, PredPropR$U.prob.Not.enough, PredPropR$U.prob.Don.t.know)
lwrCI <- c(PredPropR$L.prob.Gone.too.far, PredPropR$L.prob.About.right, PredPropR$L.prob.Not.enough, PredPropR$L.prob.Don.t.know)
response <- rep(c("Gone too far", "About right", "Not gone far enough", "Do not know"), each=16)

df_eP3 <- data.frame(eP3,lr, populism, lwrCI, uprCI, response)
df_eP3$response <- factor(df_eP3$response, levels = c("Gone too far", "About right", "Not gone far enough", "Do not know"))


peP3_res <- ggplot(df_eP3, aes(x=lr, y = eP3)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI, fill= factor(populism)), alpha=.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "Left", "3", "4", "5", "6", "7", "8", "Right", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  facet_wrap(~response) +
  ggtitle("Do you think that measures to protect the environment\nhave gone too far or not far enough?") +
  theme(strip.background = element_rect(fill = 'white')) +
  theme(text = element_text(size=20))
peP3_res


# Ordinal Regression ------------------------------------------------------


# First Effect ------------------------------------------------------------


# Climate Change ----------------------------------------------------------

df_bes$climateChange_ord <- as.factor(ifelse(df_bes$climateChange == "Don't know", NA, df_bes$climateChange))
df_bes$climateChange_ord <- factor(df_bes$climateChange_ord, label=c("Climate changing due to human activity", "Climate changing but not due to human activity", "Climate not changing"))

mcc.1_ord <- polr(formula(paste0("climateChange_ord ~ populism + lr", cUK)), data = df_bes, weights = df_bes$wt_full_w7, Hess=TRUE)
summary(mcc.1_ord)


fit.effR <- effect("populism", mcc.1_ord, xlevels = list(populism=seq(minPop,maxPop, length.out = 10)),
                   x.var="populism", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob,
                        fit.effR$upper.prob)

#plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue"), rug=FALSE, main = "",
#     ylab = "Probability", xlab="Populismus")

cc1 <- c(PredPropR$prob.Climate.changing.due.to.human.activity, PredPropR$prob.Climate.changing.but.not.due.to.human.activity, PredPropR$prob.Climate.not.changing)
populism <- rep(PredPropR$populism,3)
lwrCI <- c(PredPropR$L.prob.Climate.changing.due.to.human.activity, PredPropR$L.prob.Climate.changing.but.not.due.to.human.activity, PredPropR$L.prob.Climate.not.changing)
uprCI <- c(PredPropR$U.prob.Climate.changing.due.to.human.activity, PredPropR$U.prob.Climate.changing.but.not.due.to.human.activity, PredPropR$U.prob.Climate.not.changing)
response <- rep(c("is changing due to human activity", "is changing but not due to human activity", "is not changing"), each=10)

df_cc1 <- data.frame(cc1,populism, lwrCI, uprCI, response)
df_cc1$response <- factor(df_cc1$response,
                          levels = c("is changing due to human activity", "is changing but not due to human activity", "is not changing"),
                          labels = c("is changing due\nto human activity", "is changing but not\ndue to human activity", "is not changing"))


pcc1_ord <- ggplot(df_cc1, aes(x=populism, y = cc1)) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI), alpha=0.5) +
  #geom_errorbar(aes(ymax=uprCI, ymin=lwrCI, colour= factor(populism))) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Level of populist attitudes") +
  #scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right")) +
  #scale_fill_manual(values=c("red", "green"),  name="Degree of Populism", labels=c("Low Populism", "High Populism")) +
  facet_wrap(~response) +
  ggtitle("On the subject of climate change do you think the world's climate ...") +
  theme(strip.background = element_rect(fill = 'white')) +
  theme(text = element_text(size=20))
pcc1_ord


# Environmental Protection ------------------------------------------------


df_bes$enviroProtection_ord <- as.factor(ifelse(df_bes$enviroProtection_RBC == "Don't know", NA, df_bes$enviroProtection_RBC))

meP.3_ord <- polr(formula(paste0("enviroProtection_ord ~ populism + lr", cUK)), data = df_bes, weights = df_bes$wt_full_w7, Hess=TRUE)
summary(meP.3_ord)

fit.effR <- effect("populism", meP.3_ord, xlevels = list(populism=seq(minPop,maxPop, length.out = 10)),
                   x.var="pop", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob, 
                        fit.effR$upper.prob)

eP1 <- c(PredPropR$prob.Gone.too.far, PredPropR$prob.About.right, PredPropR$prob.Not.enough)
populism <- rep(PredPropR$populism,3)
uprCI <- c(PredPropR$U.prob.Gone.too.far, PredPropR$U.prob.About.right, PredPropR$U.prob.Not.enough)
lwrCI <- c(PredPropR$L.prob.Gone.too.far, PredPropR$L.prob.About.right, PredPropR$L.prob.Not.enough)
response <- rep(c("Gone too far", "About right", "Not gone far enough"), each=10)

df_eP1 <- data.frame(eP1,populism, lwrCI, uprCI, response)
df_eP1$response <- factor(df_eP1$response, levels = c("Gone much too far", "Gone too far", "About right", "Not gone far enough", "Not gone nearly far enough"))


peP1_ord <- ggplot(df_eP1, aes(x=populism, y = eP1)) +
  #  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI), alpha=0.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Level of populist attitudes") +
  #scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right")) +
  #scale_fill_manual(values=c("red", "green"),  name="Degree of Populism", labels=c("Low Populism", "High Populism")) +
  facet_wrap(~response) +
  ggtitle("Do you think that measures to protect the environment\nhave gone too far or not far enough?") +
  theme(strip.background = element_rect(fill = 'white')) +
  theme(text = element_text(size=20))
peP1_ord


# plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue", "green", "grey"), rug=FALSE, main = "", 
#      ylab = "Probability", xlab="Populismus")

# Interaction -------------------------------------------------------------

# Climate Scepticism ------------------------------------------------------

df_bes$climateChange_ord <- as.factor(ifelse(df_bes$climateChange == "Don't know", NA, df_bes$climateChange))

mcc.2.ord <- polr(formula(paste0("climateChange_ord ~ populism * lr", cUK)), data = df_bes, weights = df_bes$wt_full_w7, Hess=TRUE)
summary(mcc.2.ord)

fit.effR <- effect("populism*lr", mcc.2.ord, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                              lr = seq(1,10, length.out = 10)),
                   x.var="lr", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob, 
                        fit.effR$upper.prob)

#plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue"), rug=FALSE, main = "", 
#     ylab = "Probability", xlab="Populismus")

cc2 <- c(PredPropR$prob.X1, PredPropR$prob.X2, PredPropR$prob.X3)
lr <- c(rep(PredPropR$lr, 3))
populism <- rep(c(minPop,maxPop),30)
lwrCI <- c(PredPropR$L.prob.X1, PredPropR$L.prob.X2, PredPropR$L.prob.X3)
uprCI <- c(PredPropR$U.prob.X1, PredPropR$U.prob.X2, PredPropR$U.prob.X3)
response <- rep(c("is changing due to human activity", "is changing but not due to human activity", "is not changing"), each=20)

df_cc2 <- data.frame(cc2,lr, populism, lwrCI, uprCI, response)
df_cc2$response <- factor(df_cc2$response,
                          levels = c("is changing due to human activity", "is changing but not due to human activity", "is not changing"),
                          labels = c("is changing due\nto human activity", "is changing but not\ndue to human activity", "is not changing"))

pcc2_ord <- ggplot(df_cc2, aes(x=lr, y = cc2)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI, fill= factor(populism)), alpha=.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  facet_wrap(~response) +
  ggtitle("On the subject of climate change do you think the world's climate ...") +
  theme(strip.background = element_rect(fill = 'white')) +
  theme(text = element_text(size=18))
pcc2_ord


# Environmental Protection ------------------------------------------------


df_bes$enviroProtection_ord <- as.factor(ifelse(df_bes$enviroProtection_RBC == "Don't know", NA, df_bes$enviroProtection_RBC))

meP.4_ord <- polr(formula(paste0("enviroProtection_ord ~ populism * lr", cUK)), data = df_bes, weights = df_bes$wt_full_w7, Hess=TRUE)
summary(meP.4_ord)

fit.effR <- effect("populism*lr", meP.4_ord, xlevels = list(populism=seq(minPop,maxPop, length.out = 2),
                                                        lr = seq(1,10, length.out = 10)),
                   x.var="lr", confidence.level = 0.95)

PredPropR <- data.frame(fit.effR$model.matrix, fit.effR$prob, fit.effR$lower.prob, 
                        fit.effR$upper.prob)

# plot(fit.effR, style= "stacked", colors= c("red", "orange", "yellow", "blue", "green", "grey"), rug=FALSE, main = "", 
#      ylab = "Probability", xlab="Populismus")


eP3 <- c(PredPropR$prob.Gone.too.far, PredPropR$prob.About.right, PredPropR$prob.Not.enough)
lr <- c(rep(PredPropR$lr, 3))
populism <- rep(c(-2,2),30)
uprCI <- c(PredPropR$U.prob.Gone.too.far, PredPropR$U.prob.About.right, PredPropR$U.prob.Not.enough)
lwrCI <- c(PredPropR$L.prob.Gone.too.far, PredPropR$L.prob.About.right, PredPropR$L.prob.Not.enough)
response <- rep(c("Gone too far", "About right", "Not gone far enough"), each=20)

df_eP3 <- data.frame(eP3,lr, populism, lwrCI, uprCI, response)
df_eP3$response <- factor(df_eP3$response, levels = c("Gone too far", "About right", "Not gone far enough", "Do not know"))


peP3_ord <- ggplot(df_eP3, aes(x=lr, y = eP3)) +
#  geom_line(aes(colour = factor(populism))) +
  geom_ribbon(aes(ymax=uprCI, ymin=lwrCI, fill= factor(populism)), alpha=.5) +
  theme_tufte() +
  ylab("Probability of response") +
  xlab("Political ideology") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right")) +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Degree of populism", labels=c("Low populism", "High populism")) +
  facet_wrap(~response) +
  ggtitle("Do you think that measures to protect the environment\nhave gone too far or not far enough?") +
  theme(strip.background = element_rect(fill = 'white')) +
  theme(text = element_text(size=20))
peP3_ord


# Logit for Climate Scepticism --------------------------------------------

mcc1_logit <- glm(formula(paste0("climateChange == 'Climate changing due to human activity' ~ populism + lr" , cUK)), data = df_bes, family = "binomial")
mcc2_logit <- glm(formula(paste0("climateChange == 'Climate changing due to human activity' ~ populism * lr" , cUK)), data = df_bes, family = "binomial")
